﻿using System;
using System.ComponentModel;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using DeSleeper.Client.Framework;

namespace DeSleeper.Client.SystemConfig
{
	/// <summary>
	/// Interaction logic for SystemView.xaml
	/// </summary>
    public partial class SystemView : PageViewBase<SystemViewModel>
	{
        private readonly BindingBase _wakeOnLanEnabledBinding;
		private readonly BindingBase _wakeOnlyForMagicBinding;

		public SystemView()
		{
			InitializeComponent();
			// Save the bindings because I have not yet figured out how to keep the default UI behavior from overwriting them OnClick without a subclass
			// of CheckBox
			_wakeOnLanEnabledBinding = BindingOperations.GetBinding(wakeOnLanEnabled, ToggleButton.IsCheckedProperty);
			_wakeOnlyForMagicBinding = BindingOperations.GetBinding(wakeOnlyForMagic, ToggleButton.IsCheckedProperty);
		    ViewModel.CommandCompleted += executionComplete;
		}

		void executionComplete(object sender, RunWorkerCompletedEventArgs e)
		{
            // Restore the bindings because I have not yet figured out how to keep the default UI behavior from overwriting them OnClick without a subclass
			// of CheckBox
			BindingOperations.SetBinding(wakeOnLanEnabled, ToggleButton.IsCheckedProperty, _wakeOnLanEnabledBinding);
			BindingOperations.SetBinding(wakeOnlyForMagic, ToggleButton.IsCheckedProperty, _wakeOnlyForMagicBinding);
		}
	}
}
